package com.lvy.hczn.front.business.controller;

import java.util.List;

import com.lvy.hczn.front.system.service.GoodsBoxSpecService;
import com.lvy.hczn.front.system.domain.business.GoodsBoxSpec;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lvy.hczn.front.common.annotation.Log;
import com.lvy.hczn.front.common.enums.BusinessType;
import com.lvy.hczn.front.common.core.controller.BaseController;
import com.lvy.hczn.front.common.core.domain.AjaxResult;
import com.lvy.hczn.front.common.utils.poi.ExcelUtil;
import com.lvy.hczn.front.common.core.page.TableDataInfo;

/**
 * 货箱规格管理Controller
 *
 * @author ruoyi
 * @date 2023-05-23
 */
@Controller
@RequestMapping("/system/box/spec")
public class GoodsBoxSpecController extends BaseController {
    private String prefix = "system/boxspec";

    @Autowired
    private GoodsBoxSpecService goodsBoxSpecService;

    @RequiresPermissions("system:box:spec:view")
    @GetMapping()
    public String spec() {
        return prefix + "/spec";
    }

    /**
     * 查询货箱规格管理列表
     */
    @RequiresPermissions("system:box:spec:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GoodsBoxSpec goodsBoxSpec) {
        startPage();
        List<GoodsBoxSpec> list = goodsBoxSpecService.selectGoodsBoxSpecList(goodsBoxSpec);
        return getDataTable(list);
    }

    /**
     * 导出货箱规格管理列表
     */
    @RequiresPermissions("system:box:spec:export")
    @Log(title = "货箱规格管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsBoxSpec goodsBoxSpec) {
        List<GoodsBoxSpec> list = goodsBoxSpecService.selectGoodsBoxSpecList(goodsBoxSpec);
        ExcelUtil<GoodsBoxSpec> util = new ExcelUtil<GoodsBoxSpec>(GoodsBoxSpec.class);
        return util.exportExcel(list, "货箱规格管理数据");
    }

    /**
     * 新增货箱规格管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存货箱规格管理
     */
    @RequiresPermissions("system:box:spec:add")
    @Log(title = "货箱规格管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GoodsBoxSpec goodsBoxSpec) {
        return toAjax(goodsBoxSpecService.insertGoodsBoxSpec(goodsBoxSpec));
    }

    /**
     * 修改货箱规格管理
     */
    @RequiresPermissions("system:box:spec:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        GoodsBoxSpec goodsBoxSpec = goodsBoxSpecService.selectGoodsBoxSpecById(id);
        mmap.put("goodsBoxSpec", goodsBoxSpec);
        return prefix + "/edit";
    }

    /**
     * 修改保存货箱规格管理
     */
    @RequiresPermissions("system:box:spec:edit")
    @Log(title = "货箱规格管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GoodsBoxSpec goodsBoxSpec) {
        return toAjax(goodsBoxSpecService.updateGoodsBoxSpec(goodsBoxSpec));
    }

    /**
     * 删除货箱规格管理
     */
    @RequiresPermissions("system:box:spec:remove")
    @Log(title = "货箱规格管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(goodsBoxSpecService.deleteGoodsBoxSpecByIds(ids));
    }
}
